package com.usian.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.Service.impl.ApAuthorServiceImpl;
import com.usian.api.article.AuthorControllerApi;
import com.usian.model.article.pojos.ApAuthor;
import com.usian.model.common.dtos.ResponseResult;
import jdk.nashorn.internal.ir.IfNode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.POST;

@RestController
@RequestMapping("/api/v1/author")
public class AuthorController implements AuthorControllerApi {

    @Autowired
    private ApAuthorServiceImpl apAuthorService;

    @GetMapping("/findByUserId/{id}")
    @Override
    public ApAuthor findByUserId( @PathVariable("id") Integer id) {
        return id!=null ?apAuthorService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getId,id)):null;
    }

    @PostMapping("/save")
    @Override
    public ResponseResult save(ApAuthor apAuthor) {
        if (apAuthor==null)return apAuthorService.paramError;
        apAuthorService.save(apAuthor);
        return ResponseResult.okResult(apAuthor);
    }
}
